library(rdrobust)
library(foreign)
library(plyr)
library(ggplot2)
library(rdd)


#################
# RD Figure: MAIN EFFECT (FIGURE A.3)
setwd("\\Users\\KKOSEC\\Dropbox (IFPRI)\\Ethio decentralisation\\Replication\\DHS_2000_Survey")
d <- read.table("Figure_4_Coefficients.txt",header=T)
d$pe <- d$c1
d$se <- d$c2
d$lb <- d$pe- 1.96*d$se
d$ub <- d$pe+ 1.96*d$se
d$group <- factor(d$c3,levels=c(11,10,9,8,7,6,5,4,3,2,1),
                  labels=c("Male head","Literate head","Secondary-educated head","Head age","Household size","Land owner","House owner","Multi-room house","Large livestock owner","Weight-for-height Z-score (age 0-5)","Head ethnicity's share of population")[11:1])

f1 = ggplot(data = d, aes(x = group, y = pe, width=0.5,ymin = lb, ymax = ub))
f1 = f1 + geom_pointrange(size=0.5, position = position_dodge(width=.5))
f1 = f1 + scale_shape_manual(values=c(22,22))  
f1 = f1 + scale_fill_manual(values=c("black","black"))
f1 = f1 + coord_flip()
f1 = f1 + geom_hline(yintercept=0, linetype="longdash", size=0.5)
f1 = f1 + theme(axis.text=element_text(size=8), axis.title=element_text(size=10,face="bold"))
f1 = f1 + ylab("Placebo Effect of Decentralization in 2000 with 95% C.I.") + xlab("Dependent Variable") 

f1 = f1+ theme(plot.background= element_rect(fill="grey100"),
               panel.background= element_rect(fill="grey100", color= "grey75"),
               panel.grid.major = element_line(color= "grey75"),
               panel.grid.minor = element_line(color= "grey80"),
               panel.grid.major.y = element_blank(),
               panel.grid.minor.y = element_blank(),
               panel.spacing.x = unit(12,"point"),
               axis.text = element_text(lineheight=0.5),
               legend.background = element_rect(fill="grey100")
)
print(f1)

